home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / RUN.TST / GENRUNDA.C < prev    next >
C/C++ Source or Header  |  1996-01-05  |  2KB  |  102 lines

  1. /* ============ */
  2. /* genrunda.c    */
  3. /* ============ */
  4. #include "miscdefs.h"
  5. #include <rundefs.h>
  6.  
  7. #include <string.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. static
  12. UCHAR    ChkBits[4096];
  13.  
  14. /* ==================================================================== */
  15. /* GenRunData - Generates block of distinct random variates        */
  16. /* ==================================================================== */
  17. void
  18. GenRunData(RUN_DATA_STRU * RunData)
  19. {
  20.     int     Next;
  21.     UINT    i;
  22.     int     RandFound = FALSE;
  23.  
  24.     RunData->ActGenCount  = 0;
  25.     RunData->ActRandCount = 0;
  26.  
  27.     memset(ChkBits, 0, sizeof(ChkBits));
  28.  
  29.     for (i = 0; i < RunData->NumRand; ++i)
  30.     {
  31.     RandFound = FALSE;
  32.  
  33.     do
  34.     {
  35.         Next = RunData->RandFun();
  36.  
  37.         /* --------------------------------- */
  38.         /* Bump Number of Variates Generated */
  39.         /* --------------------------------- */
  40.         ++(RunData->ActGenCount);
  41.  
  42.         /* ------------------------------ */
  43.         /* Is This is a Distinct Variate? */
  44.         /* ------------------------------ */
  45.         if (TestBit(ChkBits, Next))
  46.         {
  47.         /* --------------------------------- */
  48.         /* No.  Has Max Count Been Exceeded? */
  49.         /* --------------------------------- */
  50.         if (RunData->ActGenCount > RunData->MaxGenCount)
  51.         {
  52.             /* ---------- */
  53.             /* Yes. Punt. */
  54.             /* ---------- */
  55.             break;
  56.         }
  57.         }
  58.         else
  59.         {
  60.         /* -------------------- */
  61.         /* Variate is Distinct. */
  62.         /* -------------------- */
  63.         SetBit(ChkBits, Next, 1);
  64.  
  65.         RandFound = TRUE;
  66.         }
  67.     }
  68.     while (!RandFound);
  69.  
  70.     /* ------------------------------------------ */
  71.     /* Has Maximum Generator Count Been Exceeded? */
  72.     /* ------------------------------------------ */
  73.     if (RunData->ActGenCount > RunData->MaxGenCount)
  74.     {
  75.         /* ---------- */
  76.         /* Yes. Punt. */
  77.         /* ---------- */
  78.         break;
  79.     }
  80.  
  81.     if (!RandFound)
  82.     {
  83.         break;
  84.     }
  85.  
  86.     /* ------------------ */
  87.     /* Store Next Variate */
  88.     /* ------------------ */
  89.     RunData->RandArray[i] = Next;
  90.  
  91.     /* -------------------------------- */
  92.     /* Bump Number of Variates Retained */
  93.     /* -------------------------------- */
  94.     ++(RunData->ActRandCount);
  95.     }
  96.  
  97.     RunData->TotVariates += RunData->ActGenCount;
  98.  
  99.     RunData->CallStatus =
  100.     RandFound && (RunData->ActGenCount <= RunData->MaxGenCount);
  101. }
  102.